/*s*
 * 
 */
package com.sj.szxy.genetic.algorithm.basic;

/**
 * @author Yi Ping
 * @date 2018年4月3日 下午6:48:22 
 * @since 1.0.0
 *
 */
public class AllOnesGA {
	
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		System.out.println("start execute genetic algorithm......");
		GeneticAlgorithm ga = new GeneticAlgorithm(100, 0.01, 0.70, 20);
		Population population = ga.initPopulation(50);
		ga.evalPopulation(population);
		int generation = 1;
		while(!ga.isTerminationConditionMet(population)) {
//			System.out.println("Best solution: " + population.getFittest(0).toString());
			//TODO apply crossover
			population = ga.crossoverPopulation(population);
			//TODO apply mutation
			population = ga.mutatePopulation(population);
			ga.evalPopulation(population);
			generation++;
			
		}
		
		System.out.println("Found solution in " + generation + " generations");
		System.out.println("Best solutio: " + population.getFittest(0).toString());
		
		long end = System.currentTimeMillis();
		System.out.println("excute time is " + (end-start));
	}
}
